package org.uoss.webapp.framework.json.support;

import net.sf.json.util.PropertyFilter;

import org.uoss.core.util.ValidationUtil;

public class IgnoreFieldProcessorImpl implements PropertyFilter {

	private String[] fields;

	public IgnoreFieldProcessorImpl() {}

	public IgnoreFieldProcessorImpl(String[] fields) {
		this.fields = fields;
	}

	public boolean apply(Object source, String name, Object value) {		
		if (fields != null && fields.length > 0) {
			if(ignore(name)||ValidationUtil.isEmpty(value)) {
				return true;
			}
			else {
				return false;
			}
		}
		return false;
	}

	public boolean ignore(String name) {
		boolean b = false;
		for (String field : fields) {
			if (name.equals(field)) {
				b = true;
			}
		}
		return b;
	}

	public String[] getFields() {
		return fields;
	}

	public void setFields(String[] fields) {
		this.fields = fields;
	}
}
